<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta name="author" content="lushu">
		<title>备用金转帐</title>
		<script language="javascript" type="text/javascript" src="../script/print.js"></script>
		<script language="javascript" src="../script/common.js" type="text/javascript"></script>
		<script language="javascript" src="../script/card.js" type="text/javascript"></script>
		<script language="javascript" type="text/javascript">
			var Page;
			function initPageElements(){
				Page.readonlyTableStyle = 'col2 label6';
				Page.initOperationForm = function(result){
					var type = result.cardUser.type;
					if (type!=CardUserType.NAME || !result.customer){
						showWarning("只有个人记名卡才能进行转帐操作");
						return false;
					}
					Common.initDict(Page.operationForm.accCode,TX.AccountType.userTx());
					return true;
				}
				Page.bill = "transfer_bill";
				Page.preResult = function(result){
					showInformation("转帐成功");
				}
				Page.changeAccCode = function(){
					//更改accCode后将转帐对象信息清空?
					Page.operationForm.targetCardUserUnique.value = "";
					if(TX.TEST_MODE)
						TX.Test.listTransferTarget();
				}
			}
			
			function doTransfer(){
				if(!checkForm(operationForm))
					return;
				if (!TX.Misc.hasAny([Page.operationForm.targetAsn,Page.operationForm.targetCardUserUnique])){
					showWarning("请输入转入卡号或转入客户编号");
					return;
				}
				var data = Common.getValues(Page.operationForm);
				if (TX.Misc.greaterThan(data.amount,data.balance)){
					showWarning("转出帐户余额不足");
					return;
				}
				var target = data.targetCardUserUnique;
				if(data.targetAsn!=""){
					//target = null;
					try{
						var result = DWR.syncCall("cardMgntService.getUserInfo",data.targetAsn,target);
						target = result.cardUser.uniqueId;
						if(result.cardUser.type!=Page.userInfo.cardUser.type)
							throw new Error("转入目标客户类型和转出客户类型不匹配");
						if(target==data.cardUserUnique)
							throw new Error("转入和转出为同一帐号");
					}catch(e){
						showError(e.description);
						return;
					}
					
				}
				if (!target){
					showWarning("输入的转入卡号错误");
					return;
				}
				var confirmString = "转出帐户编号:" + data.cardUserUnique + "<br>"
									+ "帐 户 类 型:" + Common.getText('account_type',data.accCode) + "<br>"
									+ "帐 户 单 位:" + data.unit + "<br>"
									+ "转 帐 额:" + data.amount + "<br>"
									+ "转入帐户编号:" + target + "<br>"
									+ (data.targetAsn?"转入卡号:" + data.targetAsn:"");
				if(showQuestion(confirmString)){
					DWR.call("tradeService.spareTransfer",
						data.cardUserUnique,
						target,
						Page.amountInSystem(data.amount),
						data.accCode,
						TX.Trade.showResult,
						{blockScreen:true}
					);
				}else{
					Page.operationForm.amount.value="";
					Page.operationForm.amount.focus();
				}
			}
		</script>
	</head>
	
	<body onload="TX.NoCardTrade.init()">
		<div class="nav"><div id="nav"></div></div>
		<div id="searchFormDiv">	
			<div class="form">
				<div class="formTitle">请输入要转出帐户的相关信息</div>	
				<form id='searchForm' name="searchForm">
					<table cellSpacing="0" cellPadding="4" width="100%" border="0" align="center">
						<tr>
							<td>
								<label>卡&nbsp;&nbsp;&nbsp;&nbsp;号</label> 
								<input type="text" size="22" name="asn" value="" maxlength="16" onblur="checkV(this,'asn');">
								<button onclick="Page.searchForm.asn.value=TX.Trade.readAsn();checkV(Page.searchForm.asn,'asn');">读 卡</button>
							</td>
							<td>
								<label>客户编号</label> 
								<input type="text" size="22" name="cardUserUnique" value="" maxlength="18" onblur="checkV(this,'uniqueId')">
							</td>
							<td><button name="search" onclick="TX.NoCardTrade.getUserAccountInfo()">查  询</button></td>
						</tr>
					</table>
				</form>	
			</div>
		</div>
		
		<div id="operationFormDiv" style="display:none;">
			<form id="operationForm" name="operationForm">
				<div class="form">
					<div class="formTitle">帐户转帐</div>	
						<span id="readonlyInfo"></span>
						<table cellSpacing="0" cellPadding="4" width="100%" border="0" class="col2 label6">
							<tr>
								<td><label>帐户类型</label> <select name="accCode" onchange="TX.NoCardTrade.changeAccCode(this)"><option></option></select></td>
								<td><label>转 帐 额</label> <input type="text" name="amount" onblur="Page.amountValidator(this)"><span class="des">*</span></td>
							</tr>
							<tr>
								<td>
									<label>转入客户编号</label> 
									<input type="text" name="targetCardUserUnique" value="" maxlength="18" onblur="checkV(this,'uniqueId')">
								</td>
								<td>
									<label>转入卡号</label> 
									<input type="text" name="targetAsn" value="" maxlength="16" onblur="checkV(this,'asn');">
									<button onclick="Page.operationForm.targetAsn.value=TX.Trade.readAsn();checkV(Page.operationForm.targetAsn,'asn');">读 卡</button>
								</td>
							</tr>
						</table>
				</div>
				<p>
					<button name="operation" onclick="doTransfer()">转 帐</button>
					<button onclick="TX.NoCardTrade.goFirstPage()">返 回</button>
				</p>
			</form>
			<div id="transferTargetList"></div>
		</div>
		
		<div id="printSheetDiv" style="display:none;">
			<div class="form">
				<div class="formTitle">备用金转帐明细</div>
				<div id="mainTrade"></div>
			</div>
			<p>
				<!--
			<button onclick="WebPrint.preview('printArea')">打印预览</button>
			<button onclick="WebPrint.print('printArea')">打印</button>
				-->
				<button onclick="TX.NoCardTrade.goFirstPage()">返 回</button>
			</p>
		</div>
		<div id="billDiv" class="form" width="100% " style="display:none;">
			<div class="formTitle">
				<div class="l">交易凭证</div>
				<div class="r">
					<button onclick="WebPrint.preview('content')">打印预览</button>
			 		<button onclick="WebPrint.print('content')">打印</button>
			 		<button onclick="TX.NoCardTrade.goFirstPage()">返 回</button>
				</div>
			</div>
			<div  id="content"  align='center'></div>
		</div>
	</body>
</html>